<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>用户管理系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--导入核心文件-->
    <script src="../../bootstrap3/js/holder.js" type=""></script>
    <link href="../../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="../../bootstrap3/jquery-1.9.1.min.js" type=""></script>
    <script src="../../bootstrap3/js/bootstrap.js" type=""></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" href="../../bootstrap3/font-awesome-4.7.0/css/font-awesome.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
</head>
<body>
<div id="wrap">
    <div id="top_content">
        <div id="header">
            <div id="rightheader">
                <p>2009/11/20<br/></p>
            </div>
            <div id="topheader">
                <h1 id="title">
                    <span>用户管理系统</span><a href="../index.html"> - 返回首页</a>
                </h1>
            </div>
            <div id="navigation"></div>
        </div>
        <div id="content">
            <p id="whereami"></p>
            <p>
                <input type="text" placeholder="可以输入用户名/手机号/编号" name="term" class="form-control" id="inp-term"/>
                <input type="button" class="cart-del-sel btn btn-default btn-xs" value="查询" id="btn-find-Like" onclick="findAdminByTerm()"/>
                <input type="button" class="cart-del-sel btn btn-default btn-xs" value="添加用户" onclick="location='adminAdd.html'"/>
                <input type="button" class="cart-del-sel btn btn-default btn-xs" value="批量删除" id="delete-num"/>
            </p>
            <!--<h1>Welcome!</h1>-->

            <table class="table">
                <thead>
               	  <tr class="table_header">
                      <td width="8%">
                          <input type="checkbox" class="ckall" onclick="" />全选</td>
                  	  <td>登录名</td>
                  	  <td>编号</td>
                  	  <td>电话</td>
                  	  <td>状态</td>
                      <td>创建人</td>
                   	  <td>创建时间</td>
					  <td>修改人</td>
                      <td>修改时间</td>
                      <td>操作</td>
                	</tr>
                </thead>
				<tbody id="admin-list" class="table-bordered">
					<tr class="row1">
                        <td><input type="checkbox" class="ckitem" /></td>
						<td>1</td>
						<td>普通管理员</td>
						<td>超级管理员</td>
						<td>超级管理员</td>
						<td>10.50</td>
						<td>10.50</td>
						<td><a href="adminList.html">编辑</a>&nbsp;&nbsp;
							<a href="adminList.html">删除</a>
						</td>
					</tr>
					<tr class="row2">
                        <td><input type="checkbox" class="ckitem" /></td>
						<td>2</td>
						<td>普通管理员</td>
						<td>超级管理员</td>
						<td>超级管理员</td>
						<td>10.50</td>
						<td>10.50</td>
						<td><a href="adminList.html">编辑</a>&nbsp;&nbsp;
							<a href="adminList.html">删除</a>
						</td>
					</tr>
				</tbody>
            </table>
        </div>
    </div>
    <div id="footer">
        <div id="footer_bg">
            ABC@126.com
        </div>
    </div>
</div>
<script type="text/javascript">
    //当页面加载完毕时，
    $(document).ready(function () {
        //请求服务器，获取全部收货地址列表
        showAllAdminList();
    });

    function deleteByAdminId(adminId){
        $.ajax({
            "url":"/admin/delete_admin_by/"+adminId,
            "type":"post",
            "dataType":"json",
            "success":function (json) {
                if(json.state===2000){
                   showAllAdminList();
                }else{
                    alert("删除收管理员失败！"+json.message);
                }
            },
            "error":function () {
                alert("您的登录信息已过期，请重新登录！");
            }
        });
    }

    function findAdminByTerm(){
        $("#admin-list").empty();
        let term = $("#inp-term").val().replace(/(^\s*)|(\s*$)/g, "");
        if (term==""){
            term="FIND_RILE_NAME_NULL"
        }
       // console.log("roleName:"+roleName);
        $.ajax({
            "url":"/admin/get_admin_like/"+term,
            "type":"get",
            "dataType":"json",
            "success":function (json) {
                if(json.state===2000){
                   showAdminList(json);
                }else{
                    alert("查询用户失败！"+json.message);
                }
            },
            "error":function () {
                alert("您的登录信息已过期，请重新登录！");
            }
        });
    }

    function showAllAdminList() {
        $("#admin-list").empty();
        $.ajax({
            "url": "/admin/get_admin_all",
            "type": "get",
            "dataType": "json",
            "success": function (json) {
                if (json.state === 2000) {
                    let list = json.data;
                    console.log("count=" + list.length);
                    showAdminList(json);
                } else {
                    alert("获取管理员列表失败！" + json.message);
                }
            }
        });
    }

    function showAdminList(json) {
        let list = json.data;
        console.log("count=" + list.length);
        for (let i = 0; i < list.length; i++) {
            console.log(list[i].adminName);
            let html = '<tr class="row#{row}">' +
                '<td><input type="checkbox" /></td>'+
                '<td>#{adminName}</td>' +
                '<td>#{adminGrade}</td>' +
                '<td>#{phone}</td>' +
                '<td>#{state}</td>' +
                '<td>#{createdUser}</td>' +
                '<td>#{createdTime}</td>' +
                '<td>#{modifiedUser}</td>' +
                '<td>#{modifiedTime}</td>' +
                '<td>' +
                '<a class="btn btn-xs btn-info btn-default " href="adminChangeInfo.html?adminId=#{adminId}""><span class="fa fa-edit" ></span>编辑</a>&nbsp;&nbsp;' +
                '<a class="btn btn-xs add-del btn-info" onclick="deleteByAdminId(#{adminId})"><span class="fa fa-trash-o" ></span> 删除</a>' +
                '</td>' +
                '</tr>';

            html = html.replace(/#{row}/g, i%2+1);
            html = html.replace(/#{adminId}/g, list[i].adminId);
            html = html.replace(/#{adminName}/g, list[i].adminName);
            html = html.replace('#{adminGrade}', list[i].adminGrade);
            html = html.replace('#{phone}', list[i].phone);
            html = html.replace('#{state}', list[i].state);
            html = html.replace('#{createdUser}', list[i].createdUser);
            html = html.replace('#{createdTime}', list[i].createdTime);
            html = html.replace('#{modifiedUser}', list[i].modifiedUser);
            html = html.replace('#{modifiedTime}', list[i].modifiedTime);

            $("#admin-list").append(html);
        }
    }
</script>
</body>
</html>
